flutter web build JS function with external JS library

您所在的位置:网站首页 android socketio flutter web build JS function with external JS library

flutter web build JS function with external JS library

2023-04-14 09:02| 来源: 网络整理| 查看: 265

The code you provided seems to be a mix of JavaScript and Dart code. To use an external JavaScript library in a Flutter web app, you can add a script tag to the HTML file where the library is located. Here's an example:

First, download the pica.min.js file and add it to your project's assets folder.

Then, in the index.html file located in the web directory of your Flutter project, add a script tag to load the external library:

My App Finally, in your Dart code, you can use the js.context.callMethod method to call the resizeBuffer function from the external library: import 'dart:js' as js; dynamic resize(Map param) { final src = param['src']; final toWidth = param['toWidth']; // call the function in the external library using js.context.callMethod return js.context.callMethod('resizeBuffer', [js.JsObject.jsify({ 'src': src, 'toWidth': toWidth, })]); }

This code should allow you to call the resize function from your Dart code and invoke the resizeBuffer function from the external pica.min.js library.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3